<template>
  <div class="talk">
    <button @click="getTalk">获取一句</button>
    <ul>
      <li v-for="talk in talkList" :key="talk.id">{{ talk.title }}</li>
    </ul>
  </div>
</template>

<script setup lang="ts" name="LoveTalk">
import { useTalkStore } from "@/store/talk";
import { storeToRefs } from "pinia";

const talkStore = useTalkStore()
const { talkList } = storeToRefs(talkStore)
talkStore.$subscribe((mutation, state) => {
  console.log('talkStore 里面保存的数据发生了变化', mutation, state)
  localStorage.setItem('talkList', JSON.stringify(state.talkList))
})

// 方法
function getTalk() {
  talkStore.getATalk()
}
</script>

<style scoped>
.talk {
  background-color: orange;
  padding: 10px;
  border-radius: 10px;
  box-shadow: 0 0 10px;
}
select, button {
  margin: 0 5px;
  height: 25px;
}
</style>